﻿using System.Collections.Generic;
using System.Data;
using RemoteTestRunner.BusinessLogic;
using RemoteTestRunner.Contracts;

namespace RemoteTestRunner.WCFService
{
    public class RTRService : IRTRService
    {
        #region Private Attributes

        private readonly IRTRService _rtrLib = new RtrLib();

        #endregion

        #region IRTRService Members

        ///// <summary>
        ///// Gets a list of test projects.
        ///// </summary>
        ///// <returns>
        ///// A <see cref="DataTable"/> containing a list of all test projects.
        ///// </returns>
        //public DataTable GetTestProjects()
        //{
        //    return _rtrLib.GetTestProjects();
        //}

        ///// <summary>
        ///// Adds a new test.
        ///// </summary>
        ///// <param name="projectId">The Project ID the new test is associated with.</param>
        ///// <param name="name">The name of the new test.</param>
        ///// <returns>
        ///// A reference to the new test <see cref="DataRow"/>.
        ///// </returns>
        //public int AddTest(int projectId, string name)
        //{
        //    return _rtrLib.AddTest(projectId, name);
        //}

        ///// <summary>
        ///// Deletes the specified test.
        ///// </summary>
        ///// <param name="testId">The ID of the test to be deleted.</param>
        //public void DeleteTest(int testId)
        //{
        //    _rtrLib.DeleteTest(testId);
        //}

        ///// <summary>
        ///// Gets a list of tests.
        ///// </summary>
        ///// <returns>
        ///// A <see cref="DataTable"/> containing a list of all tests.
        ///// </returns>
        //public DataTable GetTests()
        //{
        //    return _rtrLib.GetTests();
        //}

        /// <summary>
        /// Gets the specified test row.
        /// </summary>
        /// <param name="testId">The ID of the test to return.</param>
        /// <returns>
        /// A <see cref="DataRow"/> containing the specified test information.
        /// </returns>
        public TestInfo GetTestRow(int testId)
        {
            return _rtrLib.GetTestRow(testId);
        }

        /// <summary>
        /// Gets a collection of data source information.
        /// </summary>
        /// <param name="appConfigPath">The application configuration file to be parsed.</param>
        /// <returns>
        /// A list of <see cref="Contracts.DataSourceInfo"/> containing information for each
        /// data source found in the configuration file.
        /// </returns>
        public List<DataSourceInfo> GetDataSources(string appConfigPath)
        {
            return _rtrLib.GetDataSources(appConfigPath);
        }

        //public DataSet GetTestData()
        //{
        //    return _rtrLib.GetTestData();
        //}

        //public void SaveTestData(DataSet dataSet)
        //{
        //    _rtrLib.SaveTestData(dataSet);
        //}

        public List<TestClass> GetTestMethods(Test test)
        {
            return _rtrLib.GetTestMethods(test);
        }

        public TestResultSummary RunTest(Project project, Test test, List<string> testsToRun, int timeoutSeconds)
        {
            return _rtrLib.RunTest(project, test, testsToRun, timeoutSeconds);
        }

        public List<TestResultSummary> GetTestResultHistory(Project project, Test test)
        {
            return _rtrLib.GetTestResultHistory(project, test);
        }

        public void DeleteTestResultHistoryItems(List<TestResultSummary> historyItemsToDelete)
        {
            _rtrLib.DeleteTestResultHistoryItems(historyItemsToDelete);
        }

        public TestResult GetTestResult(string path)
        {
            return _rtrLib.GetTestResult(path);
        }

        public List<Project> GetProjects()
        {
            return _rtrLib.GetProjects();
        }

        public void SaveProjects(List<Project> projects)
        {
            _rtrLib.SaveProjects(projects);
        }

        #endregion
    }
}